#ifndef __SOFT_LICENSE_H__
#define __SOFT_LICENSE_H__

#include "kernel/OgrePlatform.h"
#include "kernel/dll_cfg.h"
#include "kernel/string_def.h"

#include <vector>

namespace FD
{
	namespace Kernel
	{
		class SoftLicense;
		class LicensePrivate;

		class FD_Kernel_Export LicenseStatusMessage
		{
		public:
			LicenseStatusMessage()
			{};

			~LicenseStatusMessage()
			{};

		public:
			virtual void show(const String& mesStr) = 0;
		};

		class FD_Kernel_Export LicenseDriver
		{
			friend class SoftLicense;
			friend class LicensePrivate;
		public:
			LicenseDriver(LicenseStatusMessage* pMes = NULL)
			{
				this->IsValid = true;
				this->mpMessage = pMes;
			};

			~LicenseDriver()
			{
				this->IsValid = false;
			};

		public:
			bool IsValid;

		protected:
			virtual bool getLicenseType(const String& srcStr, String& dstStr) = 0;
			LicenseStatusMessage* mpMessage;
		};

		class FD_Kernel_Export SoftLicense
		{
			friend class LicensePrivate;
		public:
			SoftLicense(LicenseDriver* pDriver);
			SoftLicense(const String& lic_file_path, bool toRegister, LicenseDriver* pDriver);
			~SoftLicense();

		public:
			bool exist(const String& module)const;
			bool isValid(const String& module)const;
			bool isExpired()const;

			void getExpiredTime(uint32& year,uint32& month,uint32& day)const;
			void getUser(String& user_name,String& company)const;
			uint32 getNumModules()const;
			String getModuleName(uint32 index)const;
			bool checkTempLicense();

		public:
			static String getLicPath();
			static bool setLicPath(const String& licPath);
			static String getHardDiskNumber();
			static String getMacAddressNumber();
			static String getSerialNumber();

			static String LicenseServerIP;
			static String LicenseServerPort;

		private:
			void init(const String& lic_file, bool defaultPath, bool toRegister);

		private:
			uint32 mVersion;

			String mUser;
			String mCompany;

			uint8  mHWID_Type;
			String mHWID;

			std::vector<String> mModules;

			bool mValid;
			bool mExpired;

			uint32 mCreatedYear;
			uint32 mCreatedMonth;
			uint32 mCreatedDay;

			uint32 mExpiredYear;
			uint32 mExpiredMonth;
			uint32 mExpiredDay;

			LicenseDriver* mpDriver;
			LicensePrivate* mpPrivate;
		};
	}
}

#endif